﻿using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class gamemanager : MonoBehaviour
{
    public Text scoreT;
    public Text meterT;
    public Slider cd;
    public int score;
    public int meter = 0;
    int moveSpeed = 2;
    public float mS;
    player player;
    int deadToR = 1;
    //运行时间
    float dtime = 0f;
    public int gK;
    public Button jumpBtn;
    public Button downBtn;
    GameObject GK01;
    GameObject GK02;
    GameObject GK03;
    GameObject GK04;
    public GameObject ting;
    // 暂停菜单
    public void zhanT()
    {
        Time.timeScale = 0;
        ting.SetActive(true);
    }
    public void jiXu()
    {
        Time.timeScale = 1;
        ting.SetActive(false);
    }
    //关闭游戏
    public void Quit() {
        UnityEditor.EditorApplication.isPlaying = false;
    }
    // Start is called before the first frame update
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<player>();
        //GK01 = GameObject.GetComponentsInChildren<fashe>();
        //G = GK01;

        scoreT.text = string.Format("分数 {0}", score);
        meterT.text = string.Format("距离 {0}", meter);
        mS = moveSpeed;
    }

    // Update is called once per frame
    void Update()
    {

        dt();
        scoreT.text = string.Format("分数 {0}", score);
        meterT.text = string.Format("距离 {0}", meter);
    

    }
    //关卡跳转
    //void guankia()
    //{
    //   gK = Random.Range(1, 4);
    //    if(gK==1){
    //        GK01.she = true;
    //    }
    //    else if (gK == 2)
    //    {
    //        GK02.she = true;
    //    }
    //    else if (gK == 3)
    //    {
    //        GK03.she = true;
    //    }
    //    else{
    //        GK04.she = true;
    //    }
    //}
    
    //meter++
    void dt() {
        if (player.alive)
        {
            dtime -= Time.deltaTime;
            if (dtime <= 0)
            {
                meter++;
                dtime = 0.45f;
            }
        }
        else {
            Invoke("dead", deadToR);
                }
    }
    void dead() {
        SceneManager.LoadScene(3); }
    
}
